import 'package:sample2/model/user_info.dart';
import 'package:sample2/model/auth/login_info.dart';
import 'package:sample2/model/auth/register_info.dart';
import 'package:sample2/helper/app_helper.dart';
import 'package:sample2/utils/networking.dart';

class UserService {
  static Future<NetworkResponseObject> register(RegisterInfo registerInfo) {
    return NetworkUtil.post(
            "users/register", null, registerInfo.toParameters())
        .then((responseObject) {
      return responseObject;
    });
  }

  static Future<NetworkResponseObject> login(LoginInfo loginInfo) {
    return NetworkUtil.post("users/login", null, loginInfo.toParameters())
        .then((responseObject) {
      UserInfo userInfo = UserInfo.fromObject(responseObject.content);
      AppHelper.shared.updateUserInfo(userInfo);
      return responseObject;
      // return userInfo;
    });
  }
}
